package net.vinote.sosa.rpc.netty;

import java.util.concurrent.ConcurrentHashMap;

import io.netty.channel.Channel;
import net.vinote.sosa.rpc.AbstractSession;
import net.vinote.sosa.rpc.RpcConfig;
import net.vinote.sosa.rpc.serial.SerializableBean;

/**
 * 基于Netty实现的RPC Session
 * 
 * @author Seer
 * @version NettySession.java, v 0.1 2015年11月22日 下午2:55:50 Seer Exp.
 */
public class NettySession extends AbstractSession {

	private Channel channel;

	public NettySession(Channel channel, RpcConfig config) {
		this.channel = channel;
		this.timeout = config.getTimeout();
		synchRespMap = new ConcurrentHashMap<String, Object>();
	}

	

	protected <T> void write0(T t) {
		SerializableBean bean = new SerializableBean();
		bean.setBean(t);
		channel.writeAndFlush(bean);
	}

	@Override
	public void close() {
		channel.close();
	}

}
